﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.8.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/xing.js" type="text/javascript"></script>
<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
function searchWaiter() {
	var m = $("#sf_mobile").val();
	var c = $("#sf_company").val();
	var q = "action=2&mobile=" + m + "&comid=" + c;
	jQuery("#list1").jqGrid('setGridParam',{page:1,url:"main?" + q}).trigger("reloadGrid");
};

function initCompany() {
	$.get('main?action=14',function (data, textStatus) {
		var len = data.length;
		var ops = "<option value='0'>全  部</option>" + data.substring(8, len - 9)
		$("#sf_company").html(ops);
	});
};

function imgState(cellvalue, options, rowObject) {
	var state = rowObject[6];
	switch (state) {
	  case '0' : return "<img src='images/yellowball.gif' title='待确认'>"; break;
	  case '1' : return "<img src='images/greenball.gif' title='正常'>"; break;
	  case '2' : return "<img src='images/redball.gif' title='停止工作'>"; break;
	}
}

function setGrid() {
	jQuery("#list1").jqGrid({ 
			url:'main?action=2',
			datatype: "json",
			hidegrid: "false",
			colNames:['手机IMEI','姓名','手机号码','身份证号','公司ID','公司名称','状态','服务项目','所在区',''], 
			colModel:[ 
					{name:'imei', width:120, sortable:false, align:'right',hidden:true,editoptions:{readonly:true,size:18}}, 
					{name:'wname',width:60, sortable:false, align:'right', editable:true,editoptions:{size:8,maxlength:8}}, 
					{name:'mobile',width:100, sortable:false, align:'right',editable: true, editoptions:{size:14,maxlength:11},editrules:{required:true,number:true}},
					{name:'idcard', width:160, sortable:false, align:'right',editable: true, editoptions:{size:30,maxlength:18},editrules:{required:true}},
					{name:'comid', width:10, sortable:false, align:'right',editable: true, hidden:true, edittype:"select", editrules:{edithidden:true},editoptions:{dataUrl:'main?action=14'}},
					{name:'company', width:200, sortable:false, align:'right'},
					{name:'state',width:60, sortable:false, align:'right', editable: true, edittype:"select", formatter:'select', editoptions:{value:"0:待确认;1:正常;2:停止工作"}},
					{name:'qualify', width:360, sortable:false, align:'right'},
					{name:'district',width:80, sortable:false, align:'right',formatter:'select', editoptions:{value:"1:市辖区;2:桥东区;3:桥西区;4:高新区;5:宣化区;6:下花园区"}},
					{name:'state_i',width:45, sortable:false, align:"center",formatter:imgState}
			], 
			viewrecords: true,
			rowNum:200,
			pager: '#gridpager1', 
			editurl:'main?action=2',
			caption:"服务人员管理",
			height: 460,
			width: 1200,
			subGrid: true,
			shrinkToFit: false,
			subGridRowExpanded: function(subgrid_id, row_id) {
				var subgrid_table_id, pager_id;
				subgrid_table_id = subgrid_id+"_t";
				subgridid = subgrid_table_id;
				pager_id = "p_"+subgrid_table_id;
				var mobile = jQuery("#list1").jqGrid('getCell', row_id, 3);
				
				$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
				jQuery("#"+subgrid_table_id).jqGrid({
					url:"main?action=5&mobile="+mobile,
					datatype: "json",
					colNames: ['工单号','客户编号','姓名','性别','客户类型','服务类型','服务内容','预约服务时间','服务状态','登记时间','派单时间'],
						colModel: [
									{name:'taskid', width:60, sortable:false, align:"right"},
									{name:'cid', width:100, sortable:false, align:"right"},
									{name:'cname', width:50, sortable:false, align:"right"},
									{name:'csex',width:30, sortable:false, align:"right", formatter:'select', editoptions:{value:"F:女;M:男"}},
									{name:'ctype',width:60, sortable:false, align:"right", formatter:'select', editoptions:{value:"1:视力残疾;2:听力残疾;3:言语残疾;4:肢体残疾;5:智力残疾;6:精神残疾;7:多重残疾"}},
									{name:'cservice',width:60, sortable:false, align:"right", formatter:'select',editoptions:{value:"0:新居开荒;1:家居保洁;2:办公室保洁;3:管道疏通;4:家电维修;5:电脑维修;6:装饰装修;7:家政服务;8:家教服务;9:票务服务;10:配送服务;11:搬家服务;12:开锁服务;13:房屋维修;14:其他"}},
									{name:'note', width: 240, sortable:false, align:"right"},
									{name:'ordertime', width:120, sortable:false, align:"right"},
									{name:'state',width:65, sortable:false,align:"right", formatter:'select', editoptions:{value:"0:未分派;1:已分派;2:已开始;3:已完成;4:已冲正;5:已回访"}},
									{name:'rectime',  width:120, sortable:false, align:"right"},
									{name:'assigntime', width:120, sortable:false, align:"right"}
						],
						viewrecords: true,
						rowNum: 10,
						pager: pager_id, 
						height: '100%'
				});
			},
			subGridRowColapsed: function(subgrid_id, row_id) {
				// this function is called before removing the data
				var subgrid_table_id;
				subgrid_table_id = subgrid_id+"_t";
				jQuery("#"+subgrid_table_id).remove();
			}
	})}; 
	
	
	$(document).ready(function(){
		setGrid();
		initCompany();
		jQuery("#list1").jqGrid('navGrid','#gridpager1',{edit:false,add:false,del:false,refresh:false,search:false})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"更改", 
   		buttonicon:"ui-icon-wrench", 
   		onClickButton: function() {
			    var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
					if( gr != null )
					  jQuery("#list1").jqGrid('editGridRow',gr,{
					  	editCaption:"更改服务人员信息",
					  	bSubmit:"保存",bCancel:"取消",modal: true,
					  	closeAfterEdit:true,
					  	viewPagerButtons:false, 
					  	reloadAfterSubmit:true,
					  	afterSubmit : function(r, postdata) {
							  					var data = eval('(' + r.responseText + ')');
							  					if (data.code != 0)
							  						return [false, data.message];
							  					else
							  						return [true, data.message];
							}
					  });
					else
						showTips("请选择要更改的服务员");
			}
		})
		.jqGrid('navButtonAdd','#gridpager1',{
   		caption:"删除", 
   		buttonicon:"ui-icon-close", 
   		onClickButton: function(){
			    var gr = jQuery("#list1").jqGrid('getGridParam','selrow');
					if( gr != null )
					  jQuery("#list1").jqGrid('delGridRow', gr, {
					  	caption:"删除确认", 
					  	msg:"确定要删除这个服务员信息吗?",
					  	bSubmit:"删除",bCancel:"取消",modal: true,
					  	closeAfterEdit:true, 
					  	reloadAfterSubmit:true,
					  	afterSubmit : function(r, postdata) {
							  					var data = eval('(' + r.responseText + ')');
							  					if (data.code != 0)
							  						return [false, data.message];
							  					else
							  						return [true, data.message];
							}
					});
					else
						showTips("请选择要删除的服务员");
			}
		});
});
</script>
<body style="background-color:#d9f1cc;">

				<div id="RightPane">
					<div class="innertube">
					<table id="list1"></table>
					<div id="gridpager1"></div>
					</div>
				</div>

</body>
